<?php

namespace co2_OS\apps\sdk\dev\v0_0_0\app;

use co2_OS as kernel;
use co2\dev\v0_0_0 as api;

class readme

{
  protected
    $default_editor='gedit',
    $accepted_editors=array
    (
      'vi','vim','gedit'
    );
    
  public function
  __construct
  (
    $app,
    $version,
    $channel,
    $editor=null
  )
  
  {
    $file=kernel\sysvar::get('apps')."/$app/$channel/$version/README.txt";
    
    $editor=is_null($editor) ? $this->default_editor : $editor;
    
    if(!is_dir(dirname($file)))
    throw new api\Exception('No such app+version+channel');
    
    if(!in_array($editor,$this->accepted_editors))
    throw new api\Exception($editor.' is not an accepted editor. Use one of these: '.implode(' or ',$this->accepted_editors));
    
    `$editor $file < \`tty\` > \`tty\``;
  }
}
